package com.handinfo.android.core.graphics;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;

import com.handinfo.android.core.resource.DWSerializable;
import com.handinfo.android.core.resource.ResHead;
import com.handinfo.android.core.resource.Resource;
import com.handinfo.android.utils.Tools;

public class DWBitmap extends DWSerializable
{
	private Bitmap m_image;
	private int m_width, m_height;

	public Bitmap getImage()
	{
		return m_image;
	}

	public static DWBitmap createImage(String url)
	{
		return null;
	}

	public int getWidth()
	{
		return m_width;
	}

	public int getHeight()
	{
		return m_height;
	}

	@Override
	public void read(Resource res, DataInputStream dis) throws IOException
	{
//		byte[] data = new byte[dis.available()];
//		dis.read(data);
		m_image = Tools.createBinImage(dis);
		m_width = m_image.getWidth();
		m_height = m_image.getHeight();
		checkLoadFinished();
	}

	@Override
	public void updateComponent(ResHead head, DWSerializable component)
	{
	}

	@Override
	public void checkLoadFinished()
	{
		m_loadFinished = (m_image == null);
	}

	@Override
	public void dispose()
	{
		if (m_image != null)
			m_image.recycle();
		m_image = null;
	}
}
